<?php
require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('goodsorder');


function getManage($mid)
{
    global $dosql;
    if ($mid > 0) {
        $m = $dosql->GetOne("SELECT * FROM `#@__user` WHERE id='$mid' ORDER BY id desc");
        if (is_array($m) && isset($m['id'])) {
            return $m['truename'];
        }
    }
}


$dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=1  and is_delete=0 ", 1);
$count1 = $dosql->GetTotalRow(1); //已经派单

$dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=2   and is_delete=0  ", 2);
$count2 = $dosql->GetTotalRow(2); //维修中

$dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=3 and is_delete=0 ", 3);
$count3 = $dosql->GetTotalRow(3); //报修完成

$dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=4  and is_delete=0 ", 4);
$count4 = $dosql->GetTotalRow(4); //报修完成

$dosql->Execute("SELECT `id` FROM `#@__order` WHERE `jindu`=5 and is_delete=0  ", 5);
$count5 = $dosql->GetTotalRow(5); //报修完成


$dosql->Execute("SELECT `id` FROM `#@__order` WHERE 1  and is_delete=0 ", 6);
$count_all = $dosql->GetTotalRow(6); //报修完成

$adcode = isset($adcode) ? $adcode : ''; //地区代码
$jindu = isset($jindu) ? $jindu : '';


/*$sql = "SELECT f.*,t.dataname as typename,j.dataname as jinduname FROM `#@__order` as f
		left join `#@__cascadedata`  as t on t.datavalue=f.apply_type  
		left join `#@__cascadedata`  as j on j.datavalue=f.jindu  
		WHERE t.datagroup='type'  AND j.datagroup='jindu'  AND   f.is_delete=0  AND f.latitude!=''    AND f.jindu>0  AND f.jindu<5   ";
		
	$dosql->Execute($sql,8);
	$order_arr0=array();
	$order_info0=array();
	$jindu_arr0=array();
	while($row = $dosql->GetArray(8))
	{
		$order_arr0[]=$row['latitude'].",".$row['longitude'];
	    $order_info0[]="<h2 class='school_name'>".$row['school']."</h2><br/>".$row['truename']." ".$row['mobile']."<br/>".$row['address']."<br/>单号：".date("Ymd",$row['post_time'])."-".$row['id']."<br/>报修时间：".date("Y-m-d H:i:s",$row['post_time'])."<br/>设备：".$row['typename']."<br/>进度：".$row['jinduname']."<br/><br/><a href='javascript:;' class='btn btn-success'  onClick=dongdanshow('".$row['id']."')>点击查看</a>";
		$jindu_arr0[]=$row['jindu'];

        //获取工程师
        $m_str="";
        if($row2['manageid']!=""){
            $m_manageid=explode(",",$row2['manageid']);
            foreach ($m_manageid as $key=>$val){
                $m_str.=getManage($val);
            }
        }
        $m_arr[]=$m_str;

	}*/

// 签到 接单 数据
$sql = "SELECT f.* ,j.dataname as jinduname,o.truename as truename , o.address as address, o.school as school,o.mobile as mobile,o.post_time as post_time,o.manageid as manageid FROM `#@__order_log` as f
		left join `#@__order`  as o on o.id=f.orderid  
		left join `#@__cascadedata`  as j on j.datavalue=f.jindu  
		WHERE  j.datagroup='jindu'  AND   o.is_delete=0  AND  f.latitude!=''   AND o.jindu>0  AND o.jindu<5  ";

$dosql->Execute($sql, 9);
$order_arr2 = array();
$order_info2 = array();
$jindu_arr2 = array();
while ($row2 = $dosql->GetArray(9)) {
    $order_arr2[] = $row2['latitude'] . "," . $row2['longitude'];
    $order_info2[] = "<h2 class='school_name'>" . $row2['school'] . "</h2><br/>" . $row2['truename'] . " " . $row2['mobile'] . "<br/>" . $row2['address'] . "<br/>单号：" . date("Ymd", $row2['post_time']) . "-" . $row2['id'] . "<br/>操作时间：" . date("Y-m-d H:i:s", $row2['op_time']) . "<br/>设备：<br/>进度：" . $row2['jinduname'] . "<br/><br/><a href='javascript:;' class='btn btn-success'  onClick=dongdanshow('" . $row2['orderid'] . "')>点击查看</a>\r";
    if ($row2['qiandao'] == 'true') {
        $row2['jindu'] = 'qian';
    }
    if ($row2['jiedan'] == 'true') {
        $row2['jindu'] = 'jie';
    }
    $jindu_arr2[] = $row2['jindu'];

    //获取工程师
    $m_str = "";
    if ($row2['manageid'] != "") {
        $m_manageid = explode(",", $row2['manageid']);
        foreach ($m_manageid as $key => $val) {
            $m_str .= " " . getManage($val);
        }
    }
    $m_arr[] = $m_str;


}

$order_arr = $order_arr2;
$order_info = $order_info2;
$jindu_arr = $jindu_arr2;


?>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title> 运行概况</title>
    <meta http-equiv="refresh" content="60">
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <script type="text/javascript" src="templates/js/listajax.js"></script>
    <script type="text/javascript" src="templates/js/forms.func.js"></script>
    <script type="text/javascript" src="templates/js/loadimage.js"></script>
    <script type="text/javascript" src="templates/js/getarea.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="ui/css/bootstrap.min.css">
    <link rel="stylesheet" href="ui/css/bootstrap-theme.min.css">
    <script src="ui/js/bootstrap.min.js"></script>
    <style type="text/css">
        * { margin: 0px; padding: 0px; }

        body, button, input, select, textarea {margin: 0;padding: 0; font: 12px/16px Verdana, Helvetica, Arial, sans-serif; }

        #container { min-width: 600px; min-height: 900px; z-index: 999; }

        .school_name { font-size: 20px; margin: 0; color: #930; }

        #container h1 { position: relative; top: 20px; width: 380px; font-size: 20px; height: 40px; line-height: 40px; text-align: center; margin: 0 auto 10px auto;z-index: 9999; background: url(img/ver.png);color: #FFF; }

        .data_box { width: 220px; height: 400px; position: absolute; right: 10px; top: 120px; background: url(img/ver.png); z-index: 9999; border-radius: 10px; }

        .data_box h2 { height: 40px; line-height: 40px; color: #FFF; font-size: 20px; }

        .data_conn { width: 190px; margin: 0 auto; color: #FFF;}

        .data_conn img { width: 24px; height: 24px; margin-right: 10px;}

        .table-bordered { border: #39F !important;}
    </style>
    <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=IYNBZ-YNYWG-IE6QE-IQPNJ-J3HKV-BVBTX"></script>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>


</head>
<body>

<div id="container">
    <h1><?php echo $cfg_webname; ?>运行概况</h1>
    <div class="data_box">
        <h2>数据概况：</h2>
        <div class="data_conn">
            <table class="table table-bordered">
                <tr>
                    <td width="120"><img src="img/1.gif">报修成功</td>
                    <td width="70"><?php echo $count1; ?></td>
                </tr>
                <tr>
                    <td><img src="img/2.png">客服已确认</td>
                    <td><?php echo $count2; ?></td>
                </tr>
                <tr>
                    <td><img src="img/3.png">已派单</td>
                    <td><?php echo $count3; ?></td>
                </tr>
                <tr>
                    <td><img src="img/4.png">工程师接单</td>
                    <td><?php echo $count4; ?></td>
                </tr>
                <tr>
                    <td><img src="img/5.png">维修完成</td>
                    <td><?php echo $count5; ?></td>
                </tr>
                <tr>
                    <td>所有工单</td>
                    <td><?php echo $count_all; ?></td>
                </tr>
            </table>
            <div class=""><kbd> 注意:</kbd> 报修完成的工单较多，不在地图上展示。</div>
        </div>
    </div>
</div>



<script type="text/javascript">

    $(function () {
        //初始化地图
        center = new qq.maps.LatLng(32.976950, 114.037510);
        map = new qq.maps.Map(document.getElementById("distribution_map"), {
            center: center,
            zoom: 13,
        });
        markersArray = []
        labelsArray = []
    });




    var vm = new Vue({
        el: '#container',
        data: {
            datas: {
                count: {all: 0, doing: 5, waiting: 0, working: 99},
                map: []
            },
            timer: null
        },
        methods: {
            setTimer: function () {
                console.log('开始定时...111')
                if (this.timer == null) {
                    this.timer = setInterval(() => {
                        console.log('开始定时...每过3秒执行一次')

                        $.ajax({
                            type: 'POST',
                            url: "daping/data_map.php",
                            data: {time: Date.parse(new Date())},
                            dataType: 'JSON',
                            success: function (result) {
                                console.log(result);
                                if (result.errno == 0) {
                                    vm.datas = result.data;
                                    console.log(vm.datas);
                                    vm.$forceUpdate();
                                    getData();
                                }
                            }
                        })
                    }, 3000)
                }
            }
        },
        created: function () {
            console.log('开始定时...000')
            //this.getFamilyBase_info()
            // 每次进入界面时，先清除之前的所有定时器，然后启动新的定时器
            clearInterval(this.timer)
            this.timer = null
            this.setTimer()
        },
        destroyed: function () {
            // 每次离开当前界面时，清除定时器
            clearInterval(this.timer)
            this.timer = null
        }

    })



    //加载数据
    function getData() {
        var cssC = {
            color: "#fff",
            fontSize: "14px",
            fontWeight: "bold",
            border:"none",
            background: "rgba(25, 25, 25, 0.7)",
            padding:"5px"

        };

        /*map*/
        if (markersArray) {
            for (i in markersArray) {
                markersArray[i].setMap(null);
            }
        }
        if (labelsArray) {
            for (i in labelsArray) {
                labelsArray[i].setMap(null);
            }
        }
        var anchor = new qq.maps.Point(6, 6),
            size = new qq.maps.Size(32, 32),
            origin = new qq.maps.Point(0, 0);
        var map_data = vm.datas.map;

        for (var i = 0; i < map_data.length; i++) {
            var data_pos = map_data[i].latlngs;
            var latLng = eval(new qq.maps.LatLng(map_data[i].lat, map_data[i].lng));
            //var latLng = new LatLng(33.006170,114.015880);
            var marker = new qq.maps.Marker({
                position: latLng,
                map: map,
                icon: new qq.maps.MarkerImage('img/' + map_data[i].jindu + '.gif', size, origin, anchor)
            });
            markersArray.push(marker);

            var label = new qq.maps.Label({
                position:  latLng,
                map: map,
                content: map_data[i].manageids,
                offset: new qq.maps.Size(-25, 20),
                style: cssC
            });
            labelsArray.push(label);

            qq.maps.event.addListener(marker, 'click', function () {
                infoWin.open();
                infoWin.setContent("12345");
                infoWin.setPosition(latLng);
            });



        }
        /*map*/





    }


</script>


</body>
</html>
